package com.md.drcs.dicom.util;

import com.md.drcs.dicom.dto.UserPatientDTO;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StudyCollectUtils {

    private static int m5ctmr = 2370;
    private static int m5hospctmr = 1599;
    private static int m5us = 8801;
    private static int m5hospus = 2451;
    private static int m5jy = 7480;
    private static int m5es = 0;
    private static int m5hospes = 0;
    private static int m5print = 521;
    private static int m5nprint = 3969;

    private static int m6ctmr = 1793;
    private static int m6hospctmr = 1102;
    private static int m6us = 12411;
    private static int m6hospus = 2751;
    private static int m6jy = 77675;
    private static int m6es = 277;
    private static int m6hospes = 234;
    private static int m6print = 1710;
    private static int m6nprint = 2895;

    private static int m7ctmr = 1461;
    private static int m7hospctmr = 971;
    private static int m7us = 12694;
    private static int m7hospus = 2906;
    private static int m7jy = 75099;
    private static int m7es = 689;
    private static int m7hospes = 568;
    private static int m7print = 1767;
    private static int m7nprint = 2432;

    enum Type {
        CTMR, HOSP_CTMR, US, HOSP_US, JY, ES, HOSP_ES, PRINT, NO_PRINT
    }

    static Map<Type, Integer> m5avg = new HashMap<>();
    static Map<Type, Integer> m6avg = new HashMap<>();
    static Map<Type, Integer> m7avg = new HashMap<>();
    static Map<Type, Integer> m5mod = new HashMap<>();
    static Map<Type, Integer> m6mod = new HashMap<>();
    static Map<Type, Integer> m7mod = new HashMap<>();

    static {
        m5avg.put(Type.CTMR, avgCount(m5ctmr));
        m5avg.put(Type.HOSP_CTMR, avgCount(m5hospctmr));
        m5avg.put(Type.US, avgCount(m5us));
        m5avg.put(Type.HOSP_US, avgCount(m5hospus));
        m5avg.put(Type.JY, avgCount(m5jy));
        m5avg.put(Type.ES, avgCount(m5es));
        m5avg.put(Type.HOSP_ES, avgCount(m5hospes));
        m5avg.put(Type.PRINT, avgCount(m5print));
        m5avg.put(Type.NO_PRINT, avgCount(m5nprint));

        m5mod.put(Type.CTMR, modCount(m5ctmr));
        m5mod.put(Type.HOSP_CTMR, modCount(m5hospctmr));
        m5mod.put(Type.US, modCount(m5us));
        m5mod.put(Type.HOSP_US, modCount(m5hospus));
        m5mod.put(Type.JY, modCount(m5jy));
        m5mod.put(Type.ES, modCount(m5es));
        m5mod.put(Type.HOSP_ES, modCount(m5hospes));
        m5mod.put(Type.PRINT, modCount(m5print));
        m5mod.put(Type.NO_PRINT, modCount(m5nprint));

        m6avg.put(Type.CTMR, avgCount(m6ctmr));
        m6avg.put(Type.HOSP_CTMR, avgCount(m6hospctmr));
        m6avg.put(Type.US, avgCount(m6us));
        m6avg.put(Type.HOSP_US, avgCount(m6hospus));
        m6avg.put(Type.JY, avgCount(m6jy));
        m6avg.put(Type.ES, avgCount(m6es));
        m6avg.put(Type.HOSP_ES, avgCount(m6hospes));
        m6avg.put(Type.PRINT, avgCount(m6print));
        m6avg.put(Type.NO_PRINT, avgCount(m6nprint));

        m6mod.put(Type.CTMR, modCount(m6ctmr));
        m6mod.put(Type.HOSP_CTMR, modCount(m6hospctmr));
        m6mod.put(Type.US, modCount(m6us));
        m6mod.put(Type.HOSP_US, modCount(m6hospus));
        m6mod.put(Type.JY, modCount(m6jy));
        m6mod.put(Type.ES, modCount(m6es));
        m6mod.put(Type.HOSP_ES, modCount(m6hospes));
        m6mod.put(Type.PRINT, modCount(m6print));
        m6mod.put(Type.NO_PRINT, modCount(m6nprint));

        m7avg.put(Type.CTMR, avgCount(m7ctmr));
        m7avg.put(Type.HOSP_CTMR, avgCount(m7hospctmr));
        m7avg.put(Type.US, avgCount(m7us));
        m7avg.put(Type.HOSP_US, avgCount(m7hospus));
        m7avg.put(Type.JY, avgCount(m7jy));
        m7avg.put(Type.ES, avgCount(m7es));
        m7avg.put(Type.HOSP_ES, avgCount(m7hospes));
        m7avg.put(Type.PRINT, avgCount(m7print));
        m7avg.put(Type.NO_PRINT, avgCount(m7nprint));

        m7mod.put(Type.CTMR, modCount(m7ctmr));
        m7mod.put(Type.HOSP_CTMR, modCount(m7hospctmr));
        m7mod.put(Type.US, modCount(m7us));
        m7mod.put(Type.HOSP_US, modCount(m7hospus));
        m7mod.put(Type.JY, modCount(m7jy));
        m7mod.put(Type.ES, modCount(m7es));
        m7mod.put(Type.HOSP_ES, modCount(m7hospes));
        m7mod.put(Type.PRINT, modCount(m7print));
        m7mod.put(Type.NO_PRINT, modCount(m7nprint));
    }

    static int avgCount(int total) {
        return total / 30;
    }
    static int modCount(int total) {
        return total % 30;
    }

    public static List<UserPatientDTO> subm5ctmr(List<UserPatientDTO> list) {
        if (list.size() > m5ctmr) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5ctmr).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6ctmr(List<UserPatientDTO> list) {
        if (list.size() > m6ctmr) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6ctmr).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7ctmr(List<UserPatientDTO> list) {
        if (list.size() > m7ctmr) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7ctmr).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm5hospctmr(List<UserPatientDTO> list) {
        if (list.size() > m5hospctmr) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5hospctmr).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6hospctmr(List<UserPatientDTO> list) {
        if (list.size() > m6hospctmr) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6hospctmr).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7hospctmr(List<UserPatientDTO> list) {
        if (list.size() > m7hospctmr) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7hospctmr).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm5us(List<UserPatientDTO> list) {
        if (list.size() > m5us) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5us).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6us(List<UserPatientDTO> list) {
        if (list.size() > m6us) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6us).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7us(List<UserPatientDTO> list) {
        if (list.size() > m7us) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7us).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm5hospus(List<UserPatientDTO> list) {
        if (list.size() > m5hospus) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5hospus).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6hospus(List<UserPatientDTO> list) {
        if (list.size() > m6hospus) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6hospus).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7hospus(List<UserPatientDTO> list) {
        if (list.size() > m7hospus) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7hospus).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm5jy(List<UserPatientDTO> list) {
        if (list.size() > m5jy) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5jy).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6jy(List<UserPatientDTO> list) {
        if (list.size() > m6jy) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6jy).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7jy(List<UserPatientDTO> list) {
        if (list.size() > m7jy) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7jy).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm5es(List<UserPatientDTO> list) {
        if (list.size() > m5es) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5es).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6es(List<UserPatientDTO> list) {
        if (list.size() > m6es) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6es).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7es(List<UserPatientDTO> list) {
        if (list.size() > m7es) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7es).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm5hospes(List<UserPatientDTO> list) {
        if (list.size() > m5hospes) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5hospes).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6hospes(List<UserPatientDTO> list) {
        if (list.size() > m6hospes) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6hospes).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7hospes(List<UserPatientDTO> list) {
        if (list.size() > m7hospes) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7hospes).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm5print(List<UserPatientDTO> list) {
        if (list.size() > m5print) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5print).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6print(List<UserPatientDTO> list) {
        if (list.size() > m6print) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6print).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7print(List<UserPatientDTO> list) {
        if (list.size() > m7print) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7print).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm5nprint(List<UserPatientDTO> list) {
        if (list.size() > m5nprint) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m5nprint).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm6nprint(List<UserPatientDTO> list) {
        if (list.size() > m6nprint) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m6nprint).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }
    public static List<UserPatientDTO> subm7nprint(List<UserPatientDTO> list) {
        if (list.size() > m7nprint) {
            return list.stream().sorted(Comparator.comparing(UserPatientDTO::getsName)).limit(m7nprint).sorted(Comparator.comparing(UserPatientDTO::getnStuId).reversed()).collect(Collectors.toList());
        }
        return list;
    }

    public static int getM5ctmr() {
        return m5ctmr;
    }

    public static int getM5hospctmr() {
        return m5hospctmr;
    }

    public static int getM5us() {
        return m5us;
    }

    public static int getM5hospus() {
        return m5hospus;
    }

    public static int getM5jy() {
        return m5jy;
    }

    public static int getM5es() {
        return m5es;
    }

    public static int getM5hospes() {
        return m5hospes;
    }

    public static int getM5print() {
        return m5print;
    }

    public static int getM5nprint() {
        return m5nprint;
    }

    public static int getM6ctmr() {
        return m6ctmr;
    }

    public static int getM6hospctmr() {
        return m6hospctmr;
    }

    public static int getM6us() {
        return m6us;
    }

    public static int getM6hospus() {
        return m6hospus;
    }

    public static int getM6jy() {
        return m6jy;
    }

    public static int getM6es() {
        return m6es;
    }

    public static int getM6hospes() {
        return m6hospes;
    }

    public static int getM6print() {
        return m6print;
    }

    public static int getM6nprint() {
        return m6nprint;
    }

    public static int getM7ctmr() {
        return m7ctmr;
    }

    public static int getM7hospctmr() {
        return m7hospctmr;
    }

    public static int getM7us() {
        return m7us;
    }

    public static int getM7hospus() {
        return m7hospus;
    }

    public static int getM7jy() {
        return m7jy;
    }

    public static int getM7es() {
        return m7es;
    }

    public static int getM7hospes() {
        return m7hospes;
    }

    public static int getM7print() {
        return m7print;
    }

    public static int getM7nprint() {
        return m7nprint;
    }

    public static Map<Type, Integer> getM5avg() {
        return m5avg;
    }

    public static Map<Type, Integer> getM6avg() {
        return m6avg;
    }

    public static Map<Type, Integer> getM7avg() {
        return m7avg;
    }

    public static Map<Type, Integer> getM5mod() {
        return m5mod;
    }

    public static Map<Type, Integer> getM6mod() {
        return m6mod;
    }

    public static Map<Type, Integer> getM7mod() {
        return m7mod;
    }
}
